#!/usr/bin/env bash
# -*- encoding UTF-8 -*-
# Author: kjzhu

export PGRDIR=$(cd `dirname $0`; pwd)
export WORKDIR=${PGRDIR}/../../../../
export VERSION=$1

source ${WORKDIR}/release/docker/env.sh

# only set VERSION if not set
: ${VERSION:="latest"}

# sh custom-server script
sh ${PGRDIR}/../custom-server.sh

# Different environment release names cannot be duplicated in different namespaces of the same cluster
export RELEASE_NAME=${DOCKER_IMAGE_NAME}
export NAMESPACE=${K8S_NAMESPACE}
echo "Release name: ${RELEASE_NAME} , Namespace: ${NAMESPACE}"

export HELM_OPTS=" \
    --namespace ${NAMESPACE} \
    -f ${PGRDIR}/values.yaml \
    --set namespace=${NAMESPACE} \
    --set image.repository=${DOCKER_REGISTRY_URL}/${DOCKER_IMAGE_NAME} \
    --set image.tag=${VERSION} \
    --set environment.aliyun_logs_${RELEASE_NAME}=stdout \
    --timeout 600s \
    --wait
"

helm upgrade --install  --version ${VERSION} ${HELM_OPTS} ${RELEASE_NAME}  ${WORKDIR}/release/k8s/chart/

